<template>
	<div :data-theme="theme" class="quality-recommend">
		<useNavBar
			:title="typeInfo.name"
			color="#fff"
			:autoBack="true"
			:bgColor="navBackgroundColor"
		>
			<view
				slot="right"
				style="color: #fff"
				class="iconfont icon-more"
				@click="open"
			></view>
		</useNavBar>
		<view class="use-mp-bg"></view>
		<block v-if="Number(typeInfo.type) === 3">
			<view
				v-for="(item, index) in tempArr"
				:key="index"
				class="proImg"
				@click="toDetail(item.proId)"
			>
				<easy-loadimage
					:image-src="item.proImage"
					mode="aspectFit"
				></easy-loadimage>
			</view>
		</block>
		<block v-else>
			<!-- <view class="header">
				<view class="ht_title">{{typeInfo.name}}</view>
			</view> -->
			<view class="recommend_list">
				<view
					class="goods_item flex"
					v-for="(item, index) in tempArr"
					:key="index"
					@click="toDetail(item.proId, item.id)"
				>
					<!-- <easy-loadimage :image-src="item.image"></easy-loadimage> -->
					<image :src="item.image" mode="aspectFit"></image>
					<view class="goods_content">
						<view class="store_name line2">{{ item.storeName }}</view>
						<view v-if="!typeInfo.type" class="sold"
							>{{ Math.floor(item.sales) + Math.floor(item.ficti) || 0 }}
							{{ $t(`message.tips.sold`) }}</view
						>
						<text v-else class="ot_price">${{ item.otPrice }}</text>
						<view class="bottom-wrap">
							<view class="price"
								><statistic :value="item.price" :currency="item.currency"
							/></view>

							<view class="more_btn">{{ $t(`page.index.viewDetails`) }}</view>
						</view>
					</view>
				</view>
				<view class="loadingicon acea-row row-center-wrapper">
					<text
						class="loading iconfont icon-jiazai"
						:hidden="loading == false"
					></text>
				</view>

				<view class="text-center pb-20" v-if="!goodScroll">
					<text>{{ $t(`page.goodsList.no`) }}</text>
				</view>
			</view>
		</block>
		<tui-drawer mode="right" :visible="rightDrawer" @close="closeDrawer">
			<user-drawer @close="closeDrawer"></user-drawer>
		</tui-drawer>
	</div>
</template>
<script>
import statistic from "@/components/statistic";
import GoodList from "@/components/goodList/index";
import { getActivityList, getLeaderboard } from "@/api/store";
let app = getApp();
export default {
	name: "HotNewGoods",
	components: {
		GoodList,
		statistic,
	},
	data: function () {
		return {
			rightDrawer: false,
			circular: true,
			typeInfo: {},
			params: {
				page: 1,
				limit: 10,
				aid: 0,
			},
			loading: false,
			goodScroll: true,
			tempArr: [],
			theme: "theme3",
			navBackgroundColor: "transparent",
		};
	},
	onLoad: function (e) {
		this.typeInfo = e;
		this.typeInfo.type ? this.getGroomList() : this.leaderboard();
	},
	// 滚动监听
	onPageScroll(e) {
		console.log("onPageScroll", e);
		// 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
		uni.$emit("scroll");
		// 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
		this.scrollTop = e.scrollTop;
		if (e.scrollTop > 0) {
			this.navBackgroundColor = "#00785e";
		} else {
			this.navBackgroundColor = "transparent";
		}
	},
	methods: {
		returns: function () {
			uni.navigateBack();
		},
		open() {
			this.rightDrawer = true;
		},
		closeDrawer(e) {
			this.rightDrawer = false;
			if (!e) {
				this.rightDrawer = false;
			}
		},
		getGroomList() {
			this.loading = true;
			if (!this.goodScroll) return;
			getActivityList(this.typeInfo.id, this.params)
				.then(({ data }) => {
					this.goodScroll = data.list.length >= this.params.limit;

					this.params.page++;
					this.tempArr = this.tempArr.concat(data.list);
					this.loading = false;
				})
				.catch((err) => {
					that.loading = false;
				});
		},
		leaderboard() {
			this.loading = true;
			getLeaderboard()
				.then(({ data }) => {
					this.tempArr = data;
					this.loading = false;
				})
				.catch((err) => {
					that.loading = false;
				});
		},
		toDetail(pid, id) {
			if (this.typeInfo.type) {
				uni.navigateTo({
					url: "/pages/goods_details/index?id=" + pid,
				});
			} else {
				uni.navigateTo({
					url: "/pages/goods_details/index?id=" + id,
				});
			}
		},
	},
	onReachBottom() {
		if (this.params.page != 1) {
			this.getGroomList();
		}
	},
};
</script>
<style lang="scss" scoped>
.use-mp-bg {
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 400rpx;
	background: url("../../../static/images/bg-ranking.png") no-repeat;
	background-position: 0 -50rpx;
	background-size: auto 400rpx;
	// z-index: -22;
	border-radius: 0 0 12rpx 12rpx;
}
.sold {
	font-size: 26rpx;
	color: #888888;
	margin-top: 6rpx;
}
.proImg {
	width: 100%;
	height: 914rpx;
	image,
	::v-deep .easy-loadimage > uni-image > div,
	uni-image > img,
	::v-deep .easy-loadimage > uni-image {
		width: 100%;
		height: 914rpx;
		overflow: initial !important;
	}
}
.quality-recommend {
	background-color: #f5f5f5;
	position: relative;
	.header {
		width: 100%;
		height: 282rpx;
		background-image: url(../../static/images/list_bgimg.png);
		background-size: cover;
		background-repeat: no-repeat;
		background-color: #00785e;
		.ht_title {
			font-size: 56rpx;
			font-weight: 600;
			color: #ffffff;
			line-height: 56rpx;
			text-align: center;
			padding-top: 52rpx;
		}
	}
	.recommend_list {
		margin-top: 50rpx;
		padding: 0 30rpx 30rpx;
		// z-index: 999;
		position: relative;
		.goods_item {
			height: 280rpx;
			background: #ffffff;
			border-radius: 16rpx;
			margin-bottom: 20rpx;
			padding: 20rpx;
			image,
			.easy-loadimage {
				width: 240rpx;
				height: 240rpx;
				border-radius: 16rpx;
				overflow: hidden;
			}
			.goods_content {
				padding-left: 24rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.bottom-wrap {
					display: flex;
					justify-content: space-between;
					align-items: center;
				}
				.store_name {
					width: 370rpx;
					height: 80rpx;
					font-size: 28rpx;
					font-weight: 500;
					color: #333333;
					line-height: 40rpx;
				}
				.price {
					height: 30rpx;
					font-size: 28rpx;
					font-family: D-DIN-Bold, D-DIN;
					font-weight: bold;
					color: #eb4644;
					line-height: 30rpx;
				}
				.ot_price {
					font-size: 24rpx;
					font-family: D-DIN, D;
					color: #999999;
					padding-top: 6rpx;
					line-height: 24rpx;
					text-decoration: line-through;
				}
				.more_btn {
					margin-top: 10rpx;
					padding: 0 20rpx;
					height: 60rpx;
					text-align: center;
					line-height: 60rpx;
					font-size: 26rpx;
					color: #fff;
					background-color: #00785e;
					border-radius: 32rpx;
					display: inline-block;
				}
			}
		}
		.empty {
			height: 600rpx;
			background: #ffffff;
			border-radius: 16rpx;
		}
	}
}
.main_bg {
	@include main_bg_color(theme);
}
</style>
